<template>
	<view>
		<view :style="{'display': tipsFlag ? 'block':'none'}" v-if="waybillDetail.cancelRemark && waybillDetail.billStatus < 3">
			<view class="tips">
				<image class="tip-img" src="../../static/icon_warning.png" mode=""></image>
				<view class="tip-info">
					<view>任务取消申请被驳回。</view>
					<view class="som">驳回原因：{{waybillDetail.cancelRemark}}</view>
				</view>
				<view class="tip-btn" @click="closeTip">关闭</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css" style="justify-content: space-between;padding: 20rpx 0; border-bottom: 1rpx dashed #EEEEEE;">
				<view>车辆：{{ waybillDetail.vehicleNo }}</view>
				<view :style="{color: waybillDetail.checkinNodeName === '已取消' ? '#999' : '#2B7CFF'}">{{ waybillDetail.checkinNodeName }}</view>
			</view>
			<uni-steps style="padding-top: 40rpx;" activeColor="#2979FF" :options="waybillDetail.checkinList" :active="waybillDetail.checkinSeq - 1"></uni-steps>
			<view class="column-css" style="padding: 30rpx 0;">
				<view class="row-css" style="align-items: center;">
					<view class="view-rodio" style="background: #81D588;"></view>
					{{ waybillDetail.shippingCity }}
				</view>
				<view class="line"></view>
				<view class="row-css" style="align-items: center;">
					<view class="view-rodio" style="background: #FB8536;"></view>
					{{ waybillDetail.receiptCity }}
				</view>
			</view>
		</view>
		<view style="justify-content: end;text-align: right;color: #2B7CFF;padding-bottom: 20rpx;padding-right: 20rpx; background: #FFFFFF;" @click="onReporthistory">
			异常上报历史
		</view>
		<view class="column-css" style="background: #ffffff;padding: 0 10rpx;">
			<view class="view-cente-cle-text" style="width: 100%; padding: 20rpx; border-top: 1rpx solid #eeeeee;border-bottom: 1rpx solid #eeeeee;;">备注：<text v-if="waybillDetail.remark != ''" style="padding: 20rpx;">{{waybillDetail.remark }}</text></view>
			
		</view>
		<view style="padding: 20rpx;font-size: 24rpx;color: #666666;">托运人信息</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">联系人</view>
				<view>{{ waybillDetail.shippingUserName }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">手机号码</view>
				<view>{{ waybillDetail.shippingUserTel }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">取货地</view>
				<view>{{ waybillDetail.shippingCity }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">详细地址</view>
				<view style="display: flex;flex: 1;">{{ waybillDetail.shippingAddress }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">托运人单位</view>
				<view>{{ waybillDetail.shippingUserUnit }}</view>
			</view>
		</view>
		<view style="padding: 20rpx;font-size: 24rpx;color: #666666;">收货人信息</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">联系人</view>
				<view>{{ waybillDetail.receiptUserName }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">手机号码</view>
				<view>{{ waybillDetail.receiptUserTel }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">收货地</view>
				<view>{{ waybillDetail.receiptCity }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">详细地址</view>
				<view style="display: flex;flex: 1;">{{ waybillDetail.receiptAddress }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">收货人单位</view>
				<view>{{ waybillDetail.receiptUserUnit }}</view>
			</view>
		</view>
		<view style="padding: 20rpx;font-size: 24rpx;color: #666666;">货物信息</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">货物名称</view>
				<view>{{ waybillDetail.goodsName }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">货物类型</view>
				<view>{{ typegoods(waybillDetail.goodsType) }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">货物重量</view>
				<view>{{ waybillDetail.planShippingNum }}{{ waybillDetail.unitStr }}</view>
			</view>
		</view>
		<view style="padding: 20rpx;font-size: 24rpx;color: #666666;">运单信息</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">配载单号</view>
				<view>{{ waybillDetail.billNo }}</view>
			</view>
		</view>
		<view v-if="waybillDetail.custNo != ''" class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">客户单号</view>
				<view>{{ waybillDetail.custNo }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">创建时间</view>
				<view>{{ waybillDetail.crtTime }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">起运时间</view>
				<view>{{ waybillDetail.startTime }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">到达时间</view>
				<view>{{ waybillDetail.arriveTime }}</view>
			</view>
		</view>
		<view class="column-css view-cente">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">完成时间</view>
				<view>{{ waybillDetail.receiptTime }}</view>
			</view>
		</view>
		<!-- <view v-if="waybillDetail.status == 2 || waybillDetail.status == 3" style="padding: 20rpx;font-size: 24rpx;color: #666666;">回单信息</view> -->
		<!-- <view v-if="waybillDetail.status == 2" class="column-css">
			<view class="column-css">
				<robby-image-upload
					v-model="imageData"
					:enable-del="true"
					:enable-add="true"
					:enable-drag="false"
					:form-data="formData"
					:header="header"
					:limit="5"
					:showUploadProgress="false"
					@delete="deleteImage"
					@add="addImage"
					:server-url-delete-image="serverUrlDeleteImage"
					:server-url="serverUrl"
				></robby-image-upload>
			</view>
			<view class="row-css" style="align-items: center;margin: 20rpx 0;">
				<image style="width: 28rpx;height: 28rpx;margin: 0 20rpx;" mode="aspectFit" src="../../static/icon_caveat.png"></image>
				<view style="color: #FB8536;font-size: 24rpx;">请先上传回单照片</view>
			</view>
		</view> -->
		<view class="column-css" style="background: #FFFFFF;">
			<robby-image-upload v-model="waybillDetail.receiptCheckPictures" :enable-del="false" :enable-add="false" :enable-drag="false"></robby-image-upload>
		</view>
		<view class="row-css view-cente" style="justify-content: space-between;border-top: 1rpx solid #eeeeee;" @click="opensign(waybillDetail.signFileUrl)">
			<view class="row-css view-cente-cle">
				<view class="view-cente-cle-text">签约时间</view>
				<view>{{ waybillDetail.signTime }}</view>
			</view>
			<view v-if="waybillDetail.signFileUrl != ''" class="row-css" style="justify-content: center; align-items: center;">
				<image style="width: 40rpx;height: 35rpx;padding: 5rpx 0;" src="../../static/icon_nes.png"></image>
			</view>
			<view v-else></view>
		</view>

		<!-- <view v-for="(item, index) in imageData" :key="index" class="">{{ index }}. {{ item.substr(-14) }}</view> -->
		<view v-if="waybillDetail.billStatus != 3" class="row-css" style="text-align: right;margin: 30rpx 10rpx;padding-bottom: 30rpx;">
			<view
				v-if="waybillDetail.billStatus == 2 && waybillDetail.nextCheckinNodeName != ''"
				class="view-deltail"
				style="flex: 1;background: #FFFFFF;border: 1rpx solid #2B7CFF;color: #2B7CFF;margin-right: 12rpx;"
				@click="onReport(waybillDetail)"
			>
				异常上报
			</view>
			<view v-if="waybillDetail.billStatus == 1" class="view-deltail" style="flex: 1;background: #1aad19;" @click="onOrders(waybillDetail)">接单</view>
			<view v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.shippingStatus == 1 && waybillDetail.billStatus == 2" class="view-deltail" style="width: 30%;margin-right: 12rpx;background: #b9b9b9;color: #fff;" @click="cancelBtn(waybillDetail)">取消任务</view>
			<view v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.shippingStatus == 1 && waybillDetail.billStatus == 5" class="view-deltail" style="width: 100%;margin-right: 12rpx;background: #b9b9b9;color: #fff;" @click="cancelBtn(waybillDetail)">取消申请中</view>
			<view
				v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.billStatus == 2 "
				class="view-deltail"
				style="flex: 2;"
				
				:style="{background: waybillDetail.nextCheckinNodeName == '起运' ? '#2B7CFF' : waybillDetail.nextCheckinNodeName == '到达' ? '#FB8536' : '#00bfbf'}"
				@click="onAuthorize(waybillDetail)"
			>
				{{ waybillDetail.nextCheckinNodeName }}
			</view>
			<view v-if="waybillDetail.billStatus == 7" >
				<view
					v-if="waybillDetail.beforeCancelStatus == 2 && waybillDetail.nextCheckinNodeName != ''"
					class="view-deltail"
					style="flex: 1;background: #FFFFFF;border: 1rpx solid #2B7CFF;color: #2B7CFF;margin-right: 12rpx;"
					@click="onReport(waybillDetail)"
				>
					异常上报
				</view>
				<view v-if="waybillDetail.beforeCancelStatus == 1" class="view-deltail" style="flex: 1;background: #FB8536;" @click="onOrders(waybillDetail)">接单</view>
				<view v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.shippingStatus == 1 && waybillDetail.beforeCancelStatus == 2" class="view-deltail" style="width: 30%;margin-right: 12rpx;background: #b9b9b9;color: #fff;" @click="cancelBtn(waybillDetail)">取消任务</view>
				<view v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.shippingStatus == 1 && waybillDetail.beforeCancelStatus == 5" class="view-deltail" style="width: 100%;margin-right: 12rpx;background: #b9b9b9;color: #fff;" @click="cancelBtn(waybillDetail)">取消申请中</view>
				<view
					v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.beforeCancelStatus == 2 "
					class="view-deltail"
					style="flex: 2;background: #FB8536;"
					@click="onAuthorize(waybillDetail)"
				>
					{{ waybillDetail.nextCheckinNodeName }}
				</view>
			</view>
			<!-- <view
				v-if="waybillDetail.nextCheckinNodeName != '' && waybillDetail.billStatus == 6"
				class="view-deltail"
				style="flex: 2;background: #b9b9b9;"
			>
				已取消
			</view> -->
			<view v-if="waybillDetail.billStatus == 8"
				class="view-deltail"
				style="width: 30%;margin-right: 12rpx;background: #FFFFFF;border: 1rpx solid #FB8536;color: #FB8536;"
				@click="operateLoadingOrder(3,waybillDetail)" >
				驳回
			</view>
			<view  v-if="waybillDetail.billStatus == 8"	class="view-deltail"
				style="flex: 1;background: #FB8536;" @click="operateLoadingOrder(4,waybillDetail)" >
				确认作废
			</view>
		</view>

		<uni-popup ref="popup2" type="center">
			<view class="column-css" style="background: #FFFFFF;width: 560rpx;padding: 15rpx;">
				<view v-if="nextCheckinWriteShippedNum == 1 || nextCheckinWriteReceiptedNum == 1" style="padding: 10rpx;margin-bottom: 10rpx;text-align: center;">
					请输入装/卸货量
				</view>
				<view v-if="nextCheckinWriteShippedNum == 1" class="row-css" style="margin-left: 20rpx;">
					<input v-model="shippedNum" style="border: 1rpx solid #D7D7D7;padding: 10rpx 20rpx;" placeholder="请输入装货量" 
						:disabled="waybillDetail.unitStr === '车' || waybillDetail.unitStr === '箱'" :style="{background: waybillDetail.unitStr === '车' || waybillDetail.unitStr === '箱' ? '#ddd' : ''}" />
					<view style="margin-left: 20rpx; border: 1rpx solid #D7D7D7;padding: 10rpx 20rpx;">{{ waybillDetail.unitStr }}</view>
				</view>
				<view v-if="nextCheckinWriteReceiptedNum == 1" class="row-css" style="margin-left: 20rpx;margin-top: 20rpx;">
					<input v-model="receiptedNum" style="border: 1rpx solid #D7D7D7;padding: 10rpx 20rpx;" placeholder="请输入卸货量" 
						:disabled="waybillDetail.unitStr === '车' || waybillDetail.unitStr === '箱'" :style="{background: waybillDetail.unitStr === '车' || waybillDetail.unitStr === '箱' ? '#ddd' : ''}"/>
					<view style="margin-left: 20rpx; border: 1rpx solid #D7D7D7;padding: 10rpx 20rpx;">{{ waybillDetail.unitStr }}</view>
				</view>
				<view v-if="nextCheckinUploadPicture == 1" class="column-css" style="background: #FFFFFF;margin: 20rpx 0;">
					<scroll-view scroll-y style="max-height: 600rpx;">
						<robby-image-upload
							v-model="imageData"
							:enable-del="true"
							:enable-add="true"
							:enable-drag="false"
							:form-data="formData"
							:header="header"
							:limit="10"
							:showUploadProgress="false"
							@delete="deleteImage"
							@add="addImage"
							:server-url-delete-image="serverUrlDeleteImage"
							:server-url="serverUrl"
						></robby-image-upload>
					</scroll-view>
				</view>
				<view class="view-deltail" style="margin: 20rpx; background: #00bfbf" @click="submit()">提交</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup3" type="center">
			<view class="column-css" style="background: #FFFFFF;border-radius: 10rpx; width: 560rpx;align-items: center;padding: 15rpx 0;">
				<view style="padding: 10rpx;margin-bottom: 10rpx;">
					接单提示
				</view>
				<view class="column-css" style="text-align: center;">
					按国家货运合规标准</br>接单后请及时点击起运/到达
				</view>
				<view class="row-css" style="margin-left: -130rpx;margin-bottom: 20rpx;margin-top: 20rpx; align-items: center;">
					<checkbox :checked="ischeckbox" style="transform:scale(0.7)" @click="checkbox()" v-if="isValidCont == 0"></checkbox>
					<view style="font-weight: bold;font-size: 26rpx;" @click="oncontract(waybillDetail.loadingOrderId)" v-if="isValidCont == 0">我已同意签订该合约</view>
				</view>
				<view style="width: 100%;height: 1rpx;background: #B9B9B9;"></view>
				<view class="row-css" style="width: 100%;">
					<view class="row-css button-view" style="color: #B9B9B9;" @click="signcanal()">关闭</view>
					<view style="height: auto;width: 1rpx;background: #B9B9B9;"></view>
					<view class="row-css button-view" style="color: #007AFF;" @click="signContract()">接单</view>
				</view>
			</view>
		</uni-popup>
		<sign-modal :show="signPopShow" ref="signPop" @close="signPopShow = false"></sign-modal>
	</view>
</template>

<script>
import robbyImageUpload from '@/components/robby-image-upload/robby-image-upload.vue';
import keyboard from '../../components/mpvue-keyboard.vue';
// #ifdef APP-PLUS
// 获取 module
var locationModule = uni.requireNativePlugin('LocationModule');
// #endif
import signModal from '../index/taskhomeModal/signModal.vue'
import Gps from '../index/gps/index.js'
const gps = new Gps()
export default {
	components: { robbyImageUpload, signModal },
	data() {
		return {
			imageData: [],
			billNo: '',
			imageurl: [],
			userInfo: {},
			loadingOrderId:'',
			orderloadingOrderId: '',
			ordercheckinSeq: '',
			nextCheckinWriteShippedNum: '',
			nextCheckinWriteReceiptedNum: '',
			nextCheckinUploadPicture: '',
			current: 0,
			signChannel: 0,
			shippedNum: '',
			receiptedNum: '',
			// options: [{ title: '起运' }, { title: '到达' }, { title: '上传回单' }],
			waybillDetail: {
				// baseInfo: { status: 0 }
			},
			serverUrl: this.API + '/driverService/upload',
			serverUrlDeleteImage: '',
			array: [],
			formData: {
				fileType: '8',
				phoneNumber: uni.getStorageSync(this.DATA_KEY.userInfo).phoneNumber,
				fileId: Math.floor(Math.random() * 1259),
				ocrOrNot: '0',
				orderId: this.billNo
			},
			header: {
				'Content-Type': 'multipart/form-data;boundary=ebf9f03029db4c2799ae16b5428b06bds',
				authorization: uni.getStorageSync(this.DATA_KEY.token)
			},
			checkCode: '',
			time: 60,
			codeText: '获取验证码',
			ischeckbox: true,
			
			
			tipsFlag: true,
			
			signPopShow: false, // 是否显示签约弹窗
			
			isValidCont: null, // 企业是否配置强制校验电子签
		};
	},
	methods: {
		closeTip() {
			this.tipsFlag = false
		},
		cancelBtn(item) {
			let that = this
			let content
			let title
			let id = item.loadingOrderId
			let now = new Date().getTime()
			let orderReceivingTime = item.orderReceivingTime
			console.log(id)
			console.log(orderReceivingTime)
			console.log(now)
			if(!orderReceivingTime) {
				content = '取消任务申请将提交给企业审核，确定取消吗？任务取消后，将停止该运输任务。'
				title = '申请提交审核中……'
			}else{
				if(now > new Date(orderReceivingTime).getTime() + 1000*60*30){
					content = '取消任务申请将提交给企业审核，确定取消吗？任务取消后，将停止该运输任务。'
					title = '申请提交审核中……'
				}else{
					content = '确定取消任务吗？任务取消后，将停止该运输任务。'
					title = '取消成功！'
				}
			}
			uni.showModal({
				title: '取消任务申请',
				content: content,
				success(res) {
					if (res.confirm) {
						that.wxRequest({
							url: `${that.API}/miniApp/loadingOrder/cancelApplication?loadingOrderId=${id}`,
							method: 'GET',
							title: '申请取消中...',
							success: res => {
								uni.showToast({
									title: title,
									icon: 'none'
								});
								uni.navigateBack()
							}
						});
					}
				}
			});
		},
		deleteImage: function(e) {
			this.imageurl = e.allImages;
		},
		addImage: function(e) {
			this.imageurl = e.allImages;
		},
		typegoods: function(goodsType) {
			let goodsty = '';
			for (var i = 0; i < this.array.length; i++) {
				if (this.array[i].dicValue == goodsType) {
					goodsty = this.array[i].dicName;
				}
			}
			return goodsty;
		},
		//驳回作废3 确认作废4
		operateLoadingOrder(val,item){
			let that = this
			uni.showModal({
				title: '提示',
				content: val==3?'将驳回当前作废申请，确认吗?':'将作废当前配载单，确认吗?',
				success: function(res) {
					if (res.confirm) {
						that.wxRequest({
							url: `${that.API}/new/loadingOrder/operateLoadingOrder?loadingOrderId=${item.loadingOrderId}&operate=${val}&driverId=${uni.getStorageSync(that.DATA_KEY.userInfo).driverId}`,
							method: 'POST',
							data: {
								"loadingOrderId": item.loadingOrderId,
								"operate": val,
								"driverId": uni.getStorageSync(that.DATA_KEY.userInfo).driverId
							},
							success: res => {
								uni.showToast({
									title: '操作成功',
									icon: 'none'
								});
								that.getdetail();
							}
						})
					} else if (res.cancel) {
						console.log('取消');
					}
				}
			});
		},
		stauscolor: function(staus) {
			let color = '#2B7CFF';
			if (staus == 0) {
				color = '#2B7CFF';
			} else if (staus == 1) {
				color = '#FB8536';
			} else if (staus == 2) {
				color = '#81D487';
			} else if (staus == 3) {
				color = '#2B7CFF';
			}
			return color;
		},
		staustext: function(staus) {
			let text = '待起运';
			if (staus == 0) {
				text = '待起运';
			} else if (staus == 1) {
				text = '已起运';
			} else if (staus == 2) {
				text = '已送达';
			} else if (staus == 3) {
				text = '已完成';
			}
			return text;
		},
		staustext1: function(staus) {
			let text = '起运';
			if (staus == 0) {
				text = '起运';
			} else if (staus == 1) {
				text = '送达';
			} else if (staus == 2) {
				text = '上传回单';
			}
			return text;
		},
		checkbox: function() {
			this.ischeckbox = !this.ischeckbox;
		},
		keyboardChange(e) {
			console.log('e===============', e);
			this.platenNum = e;
			// uni.showToast({
			// 	icon: 'none',
			// 	title: e,
			// 	mask: true,
			// 	duration: 2000
			// });
		},
		oncontract(loadingOrderId){
			this.$refs.popup3.close();
			uni.navigateTo({
				url: `../task/singlesign?loadingOrderId=`+this.waybillDetail.loadingOrderId
			});
		},
		opensign(signFileUrl) {
			if(signFileUrl == ''){
				return
			}
			uni.showLoading({
				title: '合同模板加载中。。。',
				mask: true
			});
			// #ifdef MP-WEIXIN
			uni.downloadFile({
				url: signFileUrl,
				// #ifdef MP-WEIXIN
				filePath: wx.env.USER_DATA_PATH + '/一单一签运输合同.pdf', //指定的本地文件路径   一定要带文件后缀名  不然无法打开   wx.env.USER_DATA_PATH类似本地文件根目录
				// #endif
				success(res) {
					console.log('是是是： ', res);
					let data = '';
					// #ifdef MP-WEIXIN
					data = res.filePath;
					// #endif
					// #ifdef APP-PLUS
					data = res.tempFilePath;
					// #endif
					uni.openDocument({
						filePath: data,
						showMenu: true, //表示右上角是否有转发按钮
						fileType: 'pdf',
						success: function(res) {
							uni.hideLoading();
							console.log('打开文档成功');
						}
					});
				}
			});
			// #endif
			// #ifdef APP-PLUS
			plus.downloader
				.createDownload(
					signFileUrl,
					{
						filename: '_downloads/一单一签运输合同.pdf'
					},
					function(d, status) {
						// 下载完成
						if (status == 200) {
							console.log('Download success: ' + d);
							console.log('Download success: ' + d.filename);
							uni.openDocument({
								filePath: d.filename,
								showMenu: true, //表示右上角是否有转发按钮
								fileType: 'pdf',
								success: function(res) {
									uni.hideLoading();
									console.log('打开文档成功');
								}
							});
						} else {
							console.log('下载失败: ' + status);
						}
					}
				)
				.start();
			// #endif
		},
		// sendcode() {
		// 	if (this.time == 60) {
		// 		// this.projectCode = Math.floor(Math.random() * 1259);
		// 		this.timer = setInterval(() => {
		// 			this.codeText = `${this.time}s后获取验证码`;
		// 			this.time--;
		// 			if (this.time < 0) {
		// 				this.time = 60;
		// 				this.codeText = '获取验证码';
		// 				clearInterval(this.timer);
		// 			}
		// 		}, 1000);
		// 		this.wxRequest({
		// 			url: `${this.API}/miniApp/loadingOrder/signSendCode`,
		// 			method: 'POST',
		// 			data: {
		// 				loadingOrderId: this.scanloadingOrderId
		// 			},
		// 			title: '验证码发送中...',
		// 			success: res => {
		// 				this.projectCode = res.data.data.projectCode;
		// 				uni.showToast({
		// 					title: '验证码已发送',
		// 					icon: 'none'
		// 				});
		// 			}
		// 		});
		// 	}
		// },
		signcanal() {
			this.getdetail();
			this.$refs.popup3.close();
		},
		signContract: async function() {
			let that = this;
			if (!that.ischeckbox && that.isValidCont == 0) {
				uni.showToast({
					title: '请勾选同意相关条款',
					icon: 'none'
				});
				return;
			}
			that.$refs.popup3.close();
			// #ifdef APP-PLUS
			await gps.checkGpsIsOpen()
			// #endif
			// #ifdef MP-WEIXIN
			
			// #endif
			await that.receive(that.waybillDetail)
			let fenceData = await this.createCircleFenceIsSuccess(that.waybillDetail)
			if (fenceData && fenceData.data.fenceStatus == 1) {
				that.logFn(`fenceStatus=1,接单`)
				let result = await gps.startLoctionBackgroundUpdate(that.waybillDetail, that.cronJsFance, that.getdetail)
				that.getdetail()
			}
			return false
			
			// #ifdef APP-PLUS
			var result;
			result = await permision.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION');
			if(uni.getSystemInfoSync().platform == 'android'){
				if (permision.checkSystemEnableLocation() == false) {
					uni.showModal({
						title: '提示',
						content: '请开启手机gps定位,设置-隐私-位置',
						showCancel: false,
						success: function(res) {}
					});
					return;
				}
			}
			// #endif
			that.wxRequest({
				url: `${that.API}/miniApp/loadingOrder/receive`,
				method: 'POST',
				data: {
					// #ifdef MP-WEIXIN
					clickLocation: 4,
					// #endif
					// #ifdef APP-PLUS
					clickLocation: 2,
					// #endif
					loadingOrderId: that.waybillDetail.loadingOrderId,
				},
				title: '接单中...',
				success: res => {
					uni.showToast({
						title: '接单成功！',
						icon: 'none'
					});
					that.$refs.popup3.close();
					that.getdetail();
					
					that.wxRequest({
						url: `${that.API}/fance/waybillFence/createCircleFenceIsSuccess?waybillId=${that.waybillDetail.waybillId}`,
						method: 'get',
						title: '加载中...',
						success: res => {
							console.log(res.data)
							console.log(!res.data.data)
							if(res.data.data.fenceStatus == 1){
								let islocation = false;
								// #ifdef MP-WEIXIN
								uni.getSystemInfo({
									success(res) {
										var isopendingwei = res.locationEnabled;
										if (isopendingwei == false) {
											uni.showModal({
												title: '提示',
												content: '请开启手机gps定位,设置-隐私-位置',
												showCancel: false,
												success: function(res) {}
											});
										} else {
											//获取位置后台定位授权
											uni.authorize({
												scope: 'scope.userLocationBackground',
												success(infoRes) {
													uni.getSetting({
														success(res) {
															that.$forceUpdate();
															if (!res.authSetting['scope.userLocationBackground']) {
																uni.showModal({
																	title: '"司机小程序"需要获取您的当前位置',
																	content: '请点击设置->打开位置信息->使用小程序期间和离开小程序后',
																	confirmText: '设置',
																	showCancel: false,
																	success(res) {
																		if (res.confirm) {
																			uni.openSetting({
																				success(res) {}
																			});
																		}
																	}
																});
															} else {
																
																islocation = true;
																uni.setStorageSync(that.DATA_KEY.loadingOrderId, that.waybillDetail.loadingOrderId);
																wx.startLocationUpdateBackground({
																	success: res => {
																		console.log(res)
																		wx.onLocationChange(data => {
																			var currentTime = new Date().getTime();
																			var oldTime = uni.getStorageSync(that.DATA_KEY.timeOld);
																			console.log(currentTime, oldTime, currentTime - oldTime > 180000);
																			if (currentTime - oldTime > 180000) {
																				uni.setStorageSync(that.DATA_KEY.timeOld, currentTime);
																				that.wxRequest({
																					url: `${that.API}/fance/waybillFence/cronJsFance`,
																					method: 'POST',
																					data: {
																						vehicleNo: taskvalue.vehicleNo,
																						driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																						trackType: 2,
																						driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																						loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
																						lat: data.latitude,
																						lng: data.longitude
																					},
																					success: res => {
																						console.log(res)
																					}
																				});
																			}
																		});
																	},
																	fail: res => {
																		console.log('获取位置失败', res);
																	}
																});
															}
														}
													});
												},
												fail(res) {
													uni.showModal({
														title: '"司机小程序"需要获取您的当前位置',
														content: '请点击设置->打开位置信息->使用小程序期间和离开小程序后',
														confirmText: '设置',
														showCancel: false,
														success(res) {
															if (res.confirm) {
																uni.openSetting({
																	success(res) {}
																});
															}
														}
													});
												}
											});
										}
									}
								});
								// #endif
								// #ifdef APP-PLUS
								if(uni.getSystemInfoSync().platform == 'android'){
									if (permision.checkSystemEnableLocation() == false) {
										uni.showModal({
											title: '提示',
											content: '请开启手机gps定位,设置-隐私-位置',
											showCancel: false,
											success: function(res) {}
										});
										return;
									} else {
										if (result == 1) {
											that.$forceUpdate();
											islocation = true;
											// #ifdef APP-PLUS
											locationModule.start(
												{
													appSecurity:taskvalue.appSecurity,
													enterpriseSenderCode:taskvalue.enterpriseSenderCode,
													ShippingNoteNumber: taskvalue.loadingOrderId,
													StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
													EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
													StartLongitude: taskvalue.StartLongitude,
													StartLatitude: taskvalue.StartLatitude,
													EndLongitude: taskvalue.EndLongitude,
													EndLatitude: taskvalue.EndLatitude,
													StartLocationText: taskvalue.shippingCity,
													EndLocationText: taskvalue.receiptCity,
													VehicleNumber: taskvalue.vehicleNo,
													DriverName: taskvalue.driverName
												},
												ret => {
													let rets = ret.code;
													uni.getLocation({
														type: 'wgs84',
														success: function(res) {
															let longitude = res.longitude;
															let latitude = res.latitude;
															if (rets == '发送定位send成功') {
																uni.setStorageSync('loadingOrderId', taskvalue.loadingOrderId);
																//发送定位回调
																uni.request({
																	url: `https://sign.y2t.com/tax/taxInfoUpload`,
																	method: 'POST',
																	data: {
																		vehicleNumber: taskvalue.vehicleNo,
																		driverName: taskvalue.driverName,
																		shippingNoteNumber: taskvalue.loadingOrderId,
																		longitude: longitude,
																		latitude: latitude,
																		status: 1
																	},
																	success: res => {
																		uni.hideLoading();
																		console.log('发送定位回调结果', res);
																	},
																	fail: error => {
																		uni.hideLoading();
																		uni.showToast({
																			title: '网络异常！',
																			icon: 'none'
																		});
																	},
																	complete: res => {
																		if (obj.complete) obj.complete(res);
																	}
																});
																console.log('====================================', taskvalue.loadingOrderId);
															}
															//上传坐标点
															let currentTime = new Date().getTime();
															let Trajectory = []
															let Trajectoryinfo = {
																lat: latitude,
																lng: longitude,
																positionTime: currentTime
															};
															Trajectory.push(Trajectoryinfo);
															uni.setStorageSync('Trajectory', Trajectory);
															that.wxRequest({
																url: `${that.API}/driverService/uploadMinilocus`,
																method: 'POST',
																data: {
																	trackType: 3,
																	loadingOrderId: taskvalue.loadingOrderId,
																	list: Trajectory,
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																},
																success: res => {
																	console.log('上传坐标点成功', res)
																	Trajectory = [];
																	uni.setStorageSync('Trajectory', Trajectory);
																},
																fail: error => {
																	console.log('上传坐标点失败')
																	Trajectory = [];
																	uni.setStorageSync('Trajectory', Trajectory);
																},
															});
														},
														fail: (err) => {
															uni.showToast({title:"位置定位失败，请查看定位权限是否开启",icon:"none"})
														}
													});
													console.log('发送定位结果', ret.code);
												}
											);
											that.Interval = setInterval(() => {
												
												// 调用异步方法启动定位
												console.log('d======================调用异步方法启动定位 ');
												locationModule.start(
													{
														appSecurity:taskvalue.appSecurity,
														enterpriseSenderCode:taskvalue.enterpriseSenderCode,
														ShippingNoteNumber: taskvalue.loadingOrderId,
														StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
														EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
														StartLongitude: taskvalue.StartLongitude,
														StartLatitude: taskvalue.StartLatitude,
														EndLongitude: taskvalue.EndLongitude,
														EndLatitude: taskvalue.EndLatitude,
														StartLocationText: taskvalue.shippingCity,
														EndLocationText: taskvalue.receiptCity,
														VehicleNumber: taskvalue.vehicleNo,
														DriverName: taskvalue.driverName
													},
													ret => {
														let rets = ret.code;
														uni.getLocation({
															type: 'wgs84',
															success: function(res) {
																let longitude = res.longitude;
																let latitude = res.latitude;
																if (rets == '发送定位send成功') {
																	uni.setStorageSync('loadingOrderId', taskvalue.loadingOrderId);
																	//发送定位回调
																	uni.request({
																		url: `https://sign.y2t.com/tax/taxInfoUpload`,
																		method: 'POST',
																		data: {
																			vehicleNumber: taskvalue.vehicleNo,
																			driverName: taskvalue.driverName,
																			shippingNoteNumber: taskvalue.loadingOrderId,
																			longitude: longitude,
																			latitude: latitude,
																			status: 1
																		},
																		success: res => {
																			uni.hideLoading();
																			console.log('发送定位回调结果', res);
																		},
																		fail: error => {
																			uni.hideLoading();
																			uni.showToast({
																				title: '网络异常！',
																				icon: 'none'
																			});
																		},
																		complete: res => {
																			if (obj.complete) obj.complete(res);
																		}
																	});
																	console.log('====================================', taskvalue.loadingOrderId);
																}
																
																//上传坐标点
																let currentTime = new Date().getTime();
																let Trajectory = []
																let Trajectoryinfo = {
																	lat: latitude,
																	lng: longitude,
																	positionTime: currentTime
																};
																Trajectory.push(Trajectoryinfo);
																uni.setStorageSync('Trajectory', Trajectory);
																that.wxRequest({
																	url: `${that.API}/driverService/uploadMinilocus`,
																	method: 'POST',
																	data: {
																		trackType: 3,
																		loadingOrderId: taskvalue.loadingOrderId,
																		list: Trajectory,
																		vehicleNo: taskvalue.vehicleNo,
																		driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																	},
																	success: res => {
																		console.log('上传坐标点成功', res)
																		Trajectory = [];
																		uni.setStorageSync('Trajectory', Trajectory);
																	},
																	fail: error => {
																		console.log('上传坐标点失败')
																		Trajectory = [];
																		uni.setStorageSync('Trajectory', Trajectory);
																	},
																});
															},
															fail: err => {
																uni.showToast({title:"位置定位失败，请查看定位权限是否开启",icon:"none"})
															}
														});
														console.log('发送定位结果', ret.code);
														// uni.showModal({
														// 	title: '提示',
														// 	content: ret.code,
														// 	showCancel: false,
														// 	success: function(res) {
														// 		if (res.confirm) {
														// 			console.log('用户点击确定');
														// 		}
														// 	}
														// });
													}
												);
											}, 180000);
											// #endif
										} else {
											uni.showModal({
												title: '该程序需要获取您的当前位置',
												confirmText: '去授权',
												showCancel: false,
												success(res) {
													if (res.confirm) {
														permision.gotoAppPermissionSetting();
													}
												}
											});
										}
									}
								}else if(uni.getSystemInfoSync().platform == 'ios'){
								
									
								}
								// #endif
							}
						}
					});
				}
			});
			// if (that.checkCode == '') {
			// 	uni.showToast({
			// 		title: '请输入验证码',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			// uni.request({
			// 	// 获取ip
			// 	url: 'https://pv.sohu.com/cityjson?ie=utf-8',
			// 	success(res) {
			// 		var m = JSON.parse(res.data.match(/.*(\{[^\}]+\}).*/)[1] || '{}');
			// 		let ip = m.cip;
			// 		console.log('ip =>', m.cip, res);
			// 		that.wxRequest({
			// 			url: `${that.API}/miniApp/loadingOrder/driverSignContract`,
			// 			method: 'POST',
			// 			data: {
			// 				loadingOrderId: that.scanloadingOrderId,
			// 				code: that.checkCode,
			// 				projectCode: that.projectCode,
			// 				ip: ip
			// 			},
			// 			title: '验证签约中...',
			// 			success: res => {
			// 				uni.showToast({
			// 					title: '签约成功！',
			// 					icon: 'none'
			// 				});
			// 				that.$refs.popup3.close();
			// 				that.getdetail();
			// 			}
			// 		});
			// 	}
			// });
		},
		onReport: function(item) {
			this.navigateTo({
				url: '../personal/abnormalreported?data=' + JSON.stringify(item)
			});
		},
		onReporthistory() {
			uni.navigateTo({
				url: `../personal/reporthistory?billNo=` + this.billNo
			});
		},
		async onOrders(taskvalue) {
			// let isSignShow = await this.$refs.signPop.beforeShow(taskvalue)
			// if (isSignShow) {
			// 	this.signPopShow = true
			// 	return
			// }
			if (this.userInfo.status != 2) {
				uni.showToast({
					title: '请在司机信息审核通过后再进行操作！',
					icon: 'none'
				});
				return;
			}
			// if (this.userInfo.isLocation == 0) {
			// 	uni.showToast({
			// 		title: '请进行基站定位授权后再进行操作！',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			// if (this.userInfo.contractStatus != 3) {
			// 	uni.showToast({
			// 		title: '请进行签约后再进行操作！',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			
			this.wxRequest({
				url: `${this.API}/driverService/checkQualifications`,
				method: 'POST',
				title: '加载中...',
				data: {
					// #ifdef MP-WEIXIN
					clickLocation: "2",
					// #endif
					// #ifdef APP-PLUS
					clickLocation: "1",
					// #endif
					driverId: uni.getStorageSync(this.DATA_KEY.userInfo).driverId,
					etpId: uni.getStorageSync(this.DATA_KEY.etpId),
					loadingOrderId: taskvalue.loadingOrderId
				},
				success: res => {
					this.isValidCont = res.data.data.isValidCont;
					// uni.setStorageSync(this.DATA_KEY.platformCoNo, res.data.data.platformCoNo);
					if (!res.data.data.flag) {
						uni.showToast({
							title: '请在首页资质认证完成后再操作！',
							icon: 'none'
						});
						return;
					} else {
						
						//	司机检测黑名单
						let that = this
						this.wxRequest({
							url: `${this.API}/blacklist/queryBlacklist`,
							method: 'POST',
							data: {
								etpId: uni.getStorageSync(this.DATA_KEY.etpId),
								typeId: "1", //id类型 1司机 2车辆
								driverVehicleId: uni.getStorageSync(this.DATA_KEY.userInfo).driverId
							},
							success:res => {
								console.log(res.data.data);
								if(res.data.data){
									uni.showModal({
										title: '禁止接单',
										content: `您已被${uni.getStorageSync(that.DATA_KEY.etpName)}列为黑名单`,
										showCancel: false,
										confirmText: '确定',
										confirmColor: '#49A9F0',
										success: function (res) {
											
										}
									});
								}else {
									//	车辆检测黑名单
									this.wxRequest({
										url: `${this.API}/blacklist/queryBlacklist`,
										method: 'POST',
										data: {
											etpId: uni.getStorageSync(this.DATA_KEY.etpId),
											typeId: "2", //id类型 1司机 2车辆
											driverVehicleId: taskvalue.vehicleId
										},
										success:res => {
											console.log(res.data.data);
											if(res.data.data){
												uni.showModal({
													title: '禁止接单',
													content: `车辆：${taskvalue.vehicleNo}已被${uni.getStorageSync(that.DATA_KEY.etpName)}列为黑名单，请更换其他车辆`,
													showCancel: false,
													confirmText: '确定',
													confirmColor: '#49A9F0',
													success: function (res) {
														
													}
												});
											}else {
												// #ifdef MP-WEIXIN
												// this.onSubscribeMessage();
												// #endif
												this.issign('', taskvalue.loadingOrderId, taskvalue.vehicleNo, 0);
											}
										}
									});
								}
							}
						});
						
						// this.issign('', taskvalue.loadingOrderId, taskvalue.vehicleNo, 0);
					}
				}
			});
		},
		issign(scanwaybillId, loadingOrderId, platenNum, model) {
			let that = this;
			that.wxRequest({
				url: `${that.API}/miniApp/loadingOrder/checkVehicleReal`,
				method: 'POST',
				data: {
					waybillId: scanwaybillId,
					plateNum: platenNum,
					loadingOrderId: loadingOrderId,
					model: model
				},
				success: res => {
					if (res.data.data.realnameState == 0) {
						uni.showToast({
							title: '司机未实名,请先进行实名操作！',
							icon: 'none'
						});
						return;
					}
					if (res.data.data.licenseState == 0) {
						uni.showToast({
							title: '车辆未认证,请先进行认证操作或更换车辆！',
							icon: 'none'
						});
						return;
					}
					// if (res.data.data.signState == 0) {
					// that.scanloadingOrderId = res.data.data.loadingOrderId;
					that.$refs.popup3.open('center');
					// } else {
					// that.wxRequest({
					// 	url: `${that.API}/miniApp/loadingOrder/receive`,
					// 	method: 'POST',
					// 	data: {
					// 		loadingOrderId: loadingOrderId
					// 	},
					// 	title: '接单中...',
					// 	success: res => {
					// 		that.getdetail();
					// 	}
					// });
					// }
				}
			});
		},
		async onAuthorize(taskvalue) {
			if (this.userInfo.status != 2) {
				uni.showToast({
					title: '请在司机信息审核通过后再进行操作！',
					icon: 'none'
				});
				return;
			}
			// if (this.userInfo.isLocation == 0) {
			// 	uni.showToast({
			// 		title: '请进行基站定位授权后再进行操作！',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			// if (this.userInfo.contractStatus != 3) {
			// 	uni.showToast({
			// 		title: '请进行签约后再进行操作！',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			let that = this;
			that.$forceUpdate();
			that.orderloadingOrderId = taskvalue.loadingOrderId;
			that.ordercheckinSeq = taskvalue.nextCheckinSeq;
			that.nextCheckinWriteShippedNum = taskvalue.nextCheckinWriteShippedNum;
			that.nextCheckinWriteReceiptedNum = taskvalue.nextCheckinWriteReceiptedNum;
			that.nextCheckinUploadPicture = taskvalue.nextCheckinUploadPicture;
			try{
				if (taskvalue.nextCheckinNodeName == '起运') {
					this.logFn(`点击起运`)
					let fenceData = await this.createCircleFenceIsSuccess(taskvalue)
					if (fenceData && fenceData.data.fenceStatus == 1) {
						let shippingStatus = await this.getShippingStatus(taskvalue)
						if (shippingStatus == 2) {
							this.page = 1;
							this.onwaybill(that.mescroll);
						} else {
							this.logFn(`fenceStatus=1`)
							uni.showModal({
								title: '提示',
								content: '未检测到您进入指定区域取货后出发，是否确认起运？',
								success: async e => {
									if (e.confirm) {
										this.logFn(`fenceStatus=1,开始获取位置`)
										let result = await gps.startLoctionBackgroundUpdate(taskvalue, this.cronJsFance, this.checkinFun)
										if (result) {
											this.checkinFun(taskvalue)
										}
									}
								}
							})
						}
					} else {
						this.logFn(`fenceStatus!=1,开始获取位置`)
						let result = await gps.startLoctionBackgroundUpdate(taskvalue, this.uploadMinilocus, this.checkinFun)
						if (result) {
							this.checkinFun(taskvalue)
						}
					}
				} else if (taskvalue.nextCheckinNodeName == '到达') {
					this.logFn(`点击到达`)
					let fenceData = await this.createCircleFenceIsSuccess(taskvalue)
					if (fenceData && fenceData.data.fenceStatus == 1) {
						let shippingStatus = await this.getShippingStatus(taskvalue)
						if (shippingStatus == 3) {
							this.page = 1;
							this.onwaybill(that.mescroll);
						} else {
							uni.showModal({
								title: '提示',
								content: '未检测到您进入指定区域送货，是否确认到达？',
								success: async e => {
									if (e.confirm) {
										this.logFn(`fenceStatus=1,开始获取位置`)
										let result = await gps.stopLocationUpdate(taskvalue, this.uploadMinilocus, this.checkinFun)
										if (result) {
											this.checkinFun(taskvalue)
										}
									}
								}
							})
						}
					} else {
						this.logFn(`fenceStatus!=1,开始获取位置`)
						let result = await gps.stopLocationUpdate(taskvalue, this.uploadMinilocus, this.checkinFun)
						if (result) {
							this.checkinFun(taskvalue)
						}
					}
				} else {
					this.checkinFun(taskvalue)
				}
			}catch(e){
				//TODO handle the exception
			}
			return 
			if (taskvalue.nextCheckinNodeName == '起运') {
				that.wxRequest({
					url: `${that.API}/fance/waybillFence/createCircleFenceIsSuccess?waybillId=${taskvalue.waybillId}`,
					method: 'get',
					title: '加载中...',
					success: res => {
						if(res.data.data && res.data.data.fenceStatus == 1){
							that.wxRequest({
								url: `${that.API}/fance/waybillFence/getShippingStatus?id=${taskvalue.loadingOrderId}`,
								method: 'get',
								title: '加载中...',
								success: re => {
									if(re.data.data.shippingStatus == 2){
										that.getdetail();
									}else{
										uni.showModal({
											title: '提示',
											content: '未检测到您进入指定区域取货后出发，是否确认起运？',
											success: res1 => {
												if (res1.confirm) {
													// #ifdef MP-WEIXIN
													uni.setStorageSync(that.DATA_KEY.loadingOrderId, taskvalue.loadingOrderId);
													let Trajectory = [];
													uni.setStorageSync('Trajectory', Trajectory);
													wx.startLocationUpdateBackground({
														success: res => {
															console.log(res)
															wx.onLocationChange(data => {
																var currentTime = new Date().getTime();
																var oldTime = uni.getStorageSync(that.DATA_KEY.timeOld);
																console.log(currentTime, oldTime, currentTime - oldTime > 180000);
																if (currentTime - oldTime > 180000) {
																	uni.setStorageSync(that.DATA_KEY.timeOld, currentTime);
																	that.wxRequest({
																		url: `${that.API}/fance/waybillFence/cronJsFance`,
																		method: 'POST',
																		data: {
																			vehicleNo: taskvalue.vehicleNo,
																			driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																			trackType: 2,
																			driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																			loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
																			lat: data.latitude,
																			lng: data.longitude
																		},
																		success: res => {
																			console.log(res)
																		}
																	});
																	
																	let Trajectory = [];
																	console.log('轨迹点0   ', uni.getStorageSync('Trajectory'));
																	console.log('轨迹点1   ', !uni.getStorageSync('Trajectory'));
																	if (uni.getStorageSync('Trajectory').length == 0) {
																		Trajectory = [];
																	} else {
																		Trajectory = uni.getStorageSync('Trajectory');
																	}
																	console.log('运单号0   ', uni.getStorageSync(that.DATA_KEY.loadingOrderId) != '');
																	let Trajectoryinfo = {
																		lat: data.latitude,
																		lng: data.longitude,
																		positionTime: currentTime
																	};
																	Trajectory.push(Trajectoryinfo);
																	uni.setStorageSync('Trajectory', Trajectory);
																	console.log('轨迹数据 ', uni.getStorageSync('Trajectory'));
																	/* that.wxRequest({
																		url: `${that.API}/driverService/uploadMinilocus`,
																		method: 'POST',
																		data: {
																			trackType: 2,
																			loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
																			list: Trajectory,
																			vehicleNo: taskvalue.vehicleNo,
																			driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																		},
																		success: res => {
																			Trajectory = [];
																			uni.setStorageSync('Trajectory', Trajectory);
																		}
																	}); */
																}
															});
														},
														fail: res => {
															console.log('获取位置失败', res);
														}
													});
													// #endif
													
													// #ifdef APP-PLUS
													uni.getLocation({
														type: 'wgs84',
														success: (res) => {
															let currentTime = new Date().getTime();
															let Trajectory = []
															let Trajectoryinfo = {
																lat: res.latitude,
																lng: res.longitude,
																positionTime: currentTime
															};
															Trajectory.push(Trajectoryinfo);
															uni.setStorageSync('Trajectory', Trajectory);
															/* that.wxRequest({
																url: `${that.API}/driverService/uploadMinilocus`,
																method: 'POST',
																data: {
																	trackType: 3,
																	loadingOrderId: taskvalue.loadingOrderId,
																	list: Trajectory,
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																},
																success: res => {
																	// uni.showModal({
																	// 	title: `${taskvalue.loadingOrderId}上传坐标点......`+JSON.stringify(res.data)
																	// })
																	Trajectory = [];
																	uni.setStorageSync('Trajectory', Trajectory);
																}
															}); */
															that.wxRequest({
																url: `${that.API}/fance/waybillFence/cronJsFance`,
																method: 'POST',
																data: {
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																	trackType: 3,
																	driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																	loadingOrderId: taskvalue.loadingOrderId,
																	lat: res.latitude,
																	lng: res.longitude
																},
																success: res => {
																	console.log(res)
																}
															});
														}
													})
													that.Interval = setInterval(() => {
														// 调用异步方法启动定位
														console.log('d======================调用异步方法启动定位 ');
														locationModule.start(
															{
																appSecurity:taskvalue.appSecurity,
																enterpriseSenderCode:taskvalue.enterpriseSenderCode,
																ShippingNoteNumber: taskvalue.loadingOrderId,
																StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
																EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
																StartLongitude: taskvalue.StartLongitude,
																StartLatitude: taskvalue.StartLatitude,
																EndLongitude: taskvalue.EndLongitude,
																EndLatitude: taskvalue.EndLatitude,
																StartLocationText: taskvalue.shippingCity,
																EndLocationText: taskvalue.receiptCity,
																VehicleNumber: taskvalue.vehicleNo,
																DriverName: taskvalue.driverName
															},
															ret => {
																let reta = ret.code;
																uni.getLocation({
																	type: 'wgs84',
																	success: function(res) {
																		let longitude = res.longitude;
																		let latitude = res.latitude;
																		if (reta == '发送定位send成功') {
																			uni.setStorageSync('loadingOrderId', taskvalue.loadingOrderId);
																			//发送定位回调
																			uni.request({
																				url: `https://sign.y2t.com/tax/taxInfoUpload`,
																				method: 'POST',
																				data: {
																					vehicleNumber: taskvalue.vehicleNo,
																					driverName: taskvalue.driverName,
																					shippingNoteNumber: taskvalue.loadingOrderId,
																					longitude: longitude,
																					latitude: latitude,
																					status: 1
																				},
																				success: res => {
																					uni.hideLoading();
																					console.log('发送定位回调结果', res);
																				},
																				fail: error => {
																					uni.hideLoading();
																					uni.showToast({
																						title: '网络异常！',
																						icon: 'none'
																					});
																				},
																				complete: res => {
																					if (obj.complete) obj.complete(res);
																				}
																			});
																			console.log('====================================', taskvalue.loadingOrderId);
																		}
																		let currentTime = new Date().getTime();
																		let Trajectory = []
																		let Trajectoryinfo = {
																			lat: latitude,
																			lng: longitude,
																			positionTime: currentTime
																		};
																		Trajectory.push(Trajectoryinfo);
																		uni.setStorageSync('Trajectory', Trajectory);
																		/* that.wxRequest({
																			url: `${that.API}/driverService/uploadMinilocus`,
																			method: 'POST',
																			data: {
																				trackType: 3,
																				loadingOrderId: taskvalue.loadingOrderId,
																				list: Trajectory,
																				vehicleNo: taskvalue.vehicleNo,
																				driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																			},
																			success: res => {
																				// uni.showModal({
																				// 	title: `${taskvalue.loadingOrderId}上传坐标点......`+JSON.stringify(res.data)
																				// })
																				Trajectory = [];
																				uni.setStorageSync('Trajectory', Trajectory);
																			}
																		}); */
																		that.wxRequest({
																			url: `${that.API}/fance/waybillFence/cronJsFance`,
																			method: 'POST',
																			data: {
																				vehicleNo: taskvalue.vehicleNo,
																				driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																				trackType: 3,
																				driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																				loadingOrderId: taskvalue.loadingOrderId,
																				lat: latitude,
																				lng: longitude
																			},
																			success: res => {
																				console.log(res)
																			}
																		});
																	}
																});
																// uni.showModal({
																// 	title: '提示',
																// 	content: ret.code,
																// 	showCancel: false,
																// 	success: function(res) {
																// 		if (res.confirm) {
																// 			console.log('用户点击确定');
																// 		}
																// 	}
																// });
															}
														);
													}, 180000);
													// #endif
													that.checkinFun(taskvalue)
												} else if (res1.cancel) {
													console.log('用户点击取消');
												}
											}
										});
									}
								}
							})
						}else{
							
							//启动定位
							// #ifdef MP-WEIXIN
							uni.setStorageSync(that.DATA_KEY.loadingOrderId, taskvalue.loadingOrderId);
							let Trajectory = [];
							uni.setStorageSync('Trajectory', Trajectory);
							wx.startLocationUpdateBackground({
								success: res => {
									console.log('轨迹点  startLocationUpdateBackground ');
									wx.onLocationChange(data => {
										console.log('轨迹点  onLocationChange ');
										var currentTime = new Date().getTime();
										var oldTime = uni.getStorageSync(that.DATA_KEY.oldTime);
										console.log('起运  时间 ', currentTime, oldTime, currentTime - oldTime > 180000);
										if (currentTime - oldTime > 180000) {
											uni.setStorageSync(that.DATA_KEY.oldTime, currentTime);
											let Trajectory = [];
											console.log('轨迹点0   ', uni.getStorageSync('Trajectory'));
											console.log('轨迹点1   ', !uni.getStorageSync('Trajectory'));
											if (uni.getStorageSync('Trajectory').length == 0) {
												Trajectory = [];
											} else {
												Trajectory = uni.getStorageSync('Trajectory');
											}
											console.log('运单号0   ', uni.getStorageSync(that.DATA_KEY.loadingOrderId) != '');
											let Trajectoryinfo = {
												lat: data.latitude,
												lng: data.longitude,
												positionTime: currentTime
											};
											Trajectory.push(Trajectoryinfo);
											uni.setStorageSync('Trajectory', Trajectory);
											console.log('轨迹数据 ', uni.getStorageSync('Trajectory'));
											that.wxRequest({
												url: `${that.API}/driverService/uploadMinilocus`,
												method: 'POST',
												data: {
													trackType: 2,
													loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
													list: Trajectory,
													vehicleNo: taskvalue.vehicleNo,
													driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
												},
												success: res => {
													Trajectory = [];
													uni.setStorageSync('Trajectory', Trajectory);
												}
											});
										}
									});
									2;
								},
								fail: res => {
									console.log('获取位置失败', res);
								}
							});
							// #endif
							// #ifdef APP-PLUS
							console.log('d======================APP-PLUS ');
							locationModule.start(
								{
									appSecurity:taskvalue.appSecurity,
									enterpriseSenderCode:taskvalue.enterpriseSenderCode,
									ShippingNoteNumber: taskvalue.loadingOrderId,
									StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
									EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
									StartLongitude: taskvalue.StartLongitude,
									StartLatitude: taskvalue.StartLatitude,
									EndLongitude: taskvalue.EndLongitude,
									EndLatitude: taskvalue.EndLatitude,
									StartLocationText: taskvalue.shippingCity,
									EndLocationText: taskvalue.receiptCity,
									VehicleNumber: taskvalue.vehicleNo,
									DriverName: taskvalue.driverName
								},
								ret => {
									let reta = ret.code;
									uni.getLocation({
										type: 'wgs84',
										success: function(res) {
											let longitude = res.longitude;
											let latitude = res.latitude;
											if (reta == '发送定位send成功') {
												uni.setStorageSync('loadingOrderId', taskvalue.loadingOrderId);
												//发送定位回调
												uni.request({
													url: `https://sign.y2t.com/tax/taxInfoUpload`,
													method: 'POST',
													data: {
														vehicleNumber: taskvalue.vehicleNo,
														driverName: taskvalue.driverName,
														shippingNoteNumber: taskvalue.loadingOrderId,
														longitude: longitude,
														latitude: latitude,
														status: 1
													},
													success: res => {
														uni.hideLoading();
														console.log('发送定位回调结果', res);
													},
													fail: error => {
														uni.hideLoading();
														uni.showToast({
															title: '网络异常！',
															icon: 'none'
														});
													},
													complete: res => {
														if (obj.complete) obj.complete(res);
													}
												});
												console.log('====================================', taskvalue.loadingOrderId);
											}
										}
									});
									console.log('发送定位结果', ret.code);
									// uni.showModal({
									// 	title: '提示',
									// 	content: ret.code,
									// 	showCancel: false,
									// 	success: function(res) {
									// 		if (res.confirm) {
									// 			console.log('用户点击确定');
									// 		}
									// 	}
									// });
								}
							);
							//上传坐标点
							uni.getLocation({
								type: 'wgs84',
								success: (res) => {
									let currentTime = new Date().getTime();
									let Trajectory = []
									let Trajectoryinfo = {
										lat: res.latitude,
										lng: res.longitude,
										positionTime: currentTime
									};
									Trajectory.push(Trajectoryinfo);
									uni.setStorageSync('Trajectory', Trajectory);
									that.wxRequest({
										url: `${that.API}/driverService/uploadMinilocus`,
										method: 'POST',
										data: {
											trackType: 3,
											loadingOrderId: taskvalue.loadingOrderId,
											list: Trajectory,
											vehicleNo: taskvalue.vehicleNo,
											driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
										},
										success: res => {
											// uni.showModal({
											// 	title: `${taskvalue.loadingOrderId}上传坐标点......`+JSON.stringify(res.data)
											// })
											Trajectory = [];
											uni.setStorageSync('Trajectory', Trajectory);
										}
									});
								}
							})
							that.Interval = setInterval(() => {
								// 调用异步方法启动定位
								console.log('d======================调用异步方法启动定位 ');
								locationModule.start(
									{
										appSecurity:taskvalue.appSecurity,
										enterpriseSenderCode:taskvalue.enterpriseSenderCode,
										ShippingNoteNumber: taskvalue.loadingOrderId,
										StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
										EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
										StartLongitude: taskvalue.StartLongitude,
										StartLatitude: taskvalue.StartLatitude,
										EndLongitude: taskvalue.EndLongitude,
										EndLatitude: taskvalue.EndLatitude,
										StartLocationText: taskvalue.shippingCity,
										EndLocationText: taskvalue.receiptCity,
										VehicleNumber: taskvalue.vehicleNo,
										DriverName: taskvalue.driverName
									},
									ret => {
										let reta = ret.code;
										uni.getLocation({
											type: 'wgs84',
											success: function(res) {
												let longitude = res.longitude;
												let latitude = res.latitude;
												if (reta == '发送定位send成功') {
													uni.setStorageSync('loadingOrderId', taskvalue.loadingOrderId);
													//发送定位回调
													uni.request({
														url: `https://sign.y2t.com/tax/taxInfoUpload`,
														method: 'POST',
														data: {
															vehicleNumber: taskvalue.vehicleNo,
															driverName: taskvalue.driverName,
															shippingNoteNumber: taskvalue.loadingOrderId,
															longitude: longitude,
															latitude: latitude,
															status: 1
														},
														success: res => {
															uni.hideLoading();
															console.log('发送定位回调结果', res);
														},
														fail: error => {
															uni.hideLoading();
															uni.showToast({
																title: '网络异常！',
																icon: 'none'
															});
														},
														complete: res => {
															if (obj.complete) obj.complete(res);
														}
													});
													console.log('====================================', taskvalue.loadingOrderId);
												}
											}
										});
										// uni.showModal({
										// 	title: '提示',
										// 	content: ret.code,
										// 	showCancel: false,
										// 	success: function(res) {
										// 		if (res.confirm) {
										// 			console.log('用户点击确定');
										// 		}
										// 	}
										// });
									}
								);
								//上传坐标点
								uni.getLocation({
									type: 'wgs84',
									success: (res) => {
										let currentTime = new Date().getTime();
										let Trajectory = []
										let Trajectoryinfo = {
											lat: res.latitude,
											lng: res.longitude,
											positionTime: currentTime
										};
										Trajectory.push(Trajectoryinfo);
										uni.setStorageSync('Trajectory', Trajectory);
										that.wxRequest({
											url: `${that.API}/driverService/uploadMinilocus`,
											method: 'POST',
											data: {
												trackType: 3,
												loadingOrderId: taskvalue.loadingOrderId,
												list: Trajectory,
												vehicleNo: taskvalue.vehicleNo,
												driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
											},
											success: res => {
												// uni.showModal({
												// 	title: `${taskvalue.loadingOrderId}上传坐标点`+JSON.stringify(res.data)
												// })
												Trajectory = [];
												uni.setStorageSync('Trajectory', Trajectory);
											}
										});
									}
								})
							}, 180000);
							// #endif
							that.checkinFun(taskvalue)
						}
					}
				})
			} else if (taskvalue.nextCheckinNodeName == '到达') {
				
				//结束定位
				that.wxRequest({
					url: `${that.API}/fance/waybillFence/createCircleFenceIsSuccess?waybillId=${taskvalue.waybillId}`,
					method: 'get',
					title: '加载中...',
					success: res => {
						if(res.data.data && res.data.data.fenceStatus == 1){
							that.wxRequest({
								url: `${that.API}/fance/waybillFence/getShippingStatus?id=${taskvalue.loadingOrderId}`,
								method: 'get',
								title: '加载中...',
								success: re => {
									if(re.data.data.shippingStatus == 3){
										that.getdetail();
									}else{
										uni.showModal({
											title: '提示',
											content: '未检测到您进入指定区域送货，是否确认到达？',
											success: res1 => {
												if (res1.confirm) {
													// #ifdef MP-WEIXIN
													uni.getLocation({
														success: (res) => {
															let currentTime = new Date().getTime();
															let Trajectory = []
															let Trajectoryinfo = {
																lat: res.latitude,
																lng: res.longitude,
																positionTime: currentTime
															};
															Trajectory.push(Trajectoryinfo);
															uni.setStorageSync('Trajectory', Trajectory);
															console.log(Trajectory)
															that.wxRequest({
																url: `${that.API}/driverService/uploadMinilocus`,
																method: 'POST',
																data: {
																	trackType: 2,
																	loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
																	list: Trajectory,
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																},
																success: res => {
																	console.log(res.data, '关闭位置成功====传值成功')
																	Trajectory = [];
																	uni.setStorageSync('Trajectory', Trajectory);
																}
															});
														},
														fail: res => {
															console.log('位置失败', res);
														}
													})
													wx.stopLocationUpdate({
														success: res => {
															console.log('关闭位置成功', res);
														},
														fail: res => {
															console.log('关闭位置失败', res);
														}
													});
													// #endif
													
													// #ifdef APP-PLUS
													clearInterval(that.Interval);
													uni.getLocation({
														type: 'wgs84',
														success: (res) => {
															let currentTime = new Date().getTime();
															let Trajectory = []
															let Trajectoryinfo = {
																lat: res.latitude,
																lng: res.longitude,
																positionTime: currentTime
															};
															Trajectory.push(Trajectoryinfo);
															uni.setStorageSync('Trajectory', Trajectory);
															that.wxRequest({
																url: `${that.API}/driverService/uploadMinilocus`,
																method: 'POST',
																data: {
																	trackType: 3,
																	loadingOrderId: taskvalue.loadingOrderId,
																	list: Trajectory,
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																},
																success: res => {
																	// uni.showModal({
																	// 	title: `${taskvalue.loadingOrderId}上传坐标点到达`+JSON.stringify(res.data)
																	// })
																	Trajectory = [];
																	uni.setStorageSync('Trajectory', Trajectory);
																}
															});
															/* that.wxRequest({
																url: `${that.API}/fance/waybillFence/cronJsFance`,
																method: 'POST',
																data: {
																	vehicleNo: taskvalue.vehicleNo,
																	driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																	trackType: 3,
																	driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																	loadingOrderId: taskvalue.loadingOrderId,
																	lat: res.latitude,
																	lng: res.longitude
																},
																success: res => {
																	console.log(res)
																}
															}); */
															
														}
													})
													locationModule.stop(
														{
															appSecurity:taskvalue.appSecurity,
															enterpriseSenderCode:taskvalue.enterpriseSenderCode,
															ShippingNoteNumber: uni.getStorageSync('loadingOrderId'),
															StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
															EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
															StartLongitude: taskvalue.StartLongitude,
															StartLatitude: taskvalue.StartLatitude,
															EndLongitude: taskvalue.EndLongitude,
															EndLatitude: taskvalue.EndLatitude,
															StartLocationText: taskvalue.shippingCity,
															EndLocationText: taskvalue.receiptCity,
															VehicleNumber: taskvalue.vehicleNo,
															DriverName: taskvalue.driverName
														},
														ret => {
															let reta = ret.code;
															uni.getLocation({
																type: 'wgs84',
																success: function(res) {
																	let longitude = res.longitude;
																	let latitude = res.latitude;
																	if (reta == '停止定位stop成功') {
																		uni.setStorageSync('loadingOrderId', '');
																		//发送定位回调
																		uni.request({
																			url: `https://sign.y2t.com/tax/taxInfoUpload`,
																			method: 'POST',
																			data: {
																				vehicleNumber: taskvalue.vehicleNo,
																				driverName: taskvalue.driverName,
																				shippingNoteNumber: taskvalue.loadingOrderId,
																				longitude: longitude,
																				latitude: latitude,
																				status: 2
																			},
																			success: res => {
																				uni.hideLoading();
																				console.log('终止定位结果', ret.code);
																			},
																			fail: error => {
																				uni.hideLoading();
																				uni.showToast({
																					title: '网络异常！',
																					icon: 'none'
																				});
																			},
																			complete: res => {
																				if (obj.complete) obj.complete(res);
																			}
																		});
																		console.log('====================================', taskvalue.loadingOrderId);
																	}
																	let currentTime = new Date().getTime();
																	let Trajectory = []
																	let Trajectoryinfo = {
																		lat: latitude,
																		lng: longitude,
																		positionTime: currentTime
																	};
																	Trajectory.push(Trajectoryinfo);
																	uni.setStorageSync('Trajectory', Trajectory);
																	that.wxRequest({
																		url: `${that.API}/driverService/uploadMinilocus`,
																		method: 'POST',
																		data: {
																			trackType: 3,
																			loadingOrderId: taskvalue.loadingOrderId,
																			list: Trajectory,
																			vehicleNo: taskvalue.vehicleNo,
																			driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
																		},
																		success: res => {
																			// uni.showModal({
																			// 	title: `${taskvalue.loadingOrderId}上传坐标点......`+JSON.stringify(res.data)
																			// })
																			Trajectory = [];
																			uni.setStorageSync('Trajectory', Trajectory);
																		}
																	});
																	/* that.wxRequest({
																		url: `${that.API}/fance/waybillFence/cronJsFance`,
																		method: 'POST',
																		data: {
																			vehicleNo: taskvalue.vehicleNo,
																			driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
																			trackType: 3,
																			driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
																			loadingOrderId: taskvalue.loadingOrderId,
																			lat: latitude,
																			lng: longitude
																		},
																		success: res => {
																			console.log(res)
																		}
																	}); */
																}
															});
														}
													);
													// #endif
													that.checkinFun(taskvalue)
												} else if (res1.cancel) {
													console.log('用户点击取消');
												}
											}
										});
									}
								}
							})
						}else{
							// #ifdef MP-WEIXIN
							uni.getLocation({
								success: (res) => {
									let Trajectoryinfo = {
										lat: res.latitude,
										lng: res.longitude,
										positionTime: currentTime
									};
									Trajectory.push(Trajectoryinfo);
									uni.setStorageSync('Trajectory', Trajectory);
									console.log(Trajectory)
									that.wxRequest({
										url: `${that.API}/driverService/uploadMinilocus`,
										method: 'POST',
										data: {
											trackType: 2,
											loadingOrderId: uni.getStorageSync(that.DATA_KEY.loadingOrderId),
											list: Trajectory,
											vehicleNo: taskvalue.vehicleNo,
											driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
										},
										success: res => {
											console.log(res.data, '关闭位置成功====传值成功')
											Trajectory = [];
											uni.setStorageSync('Trajectory', Trajectory);
										}
									});
								},
								fail: res => {
									console.log('位置失败', res);
								}
							})
							wx.stopLocationUpdate({
								success: res => {
									console.log('关闭位置成功', res);
								},
								fail: res => {
									console.log('关闭位置失败', res);
								}
							});
							// #endif
							
							// #ifdef APP-PLUS
							clearInterval(that.Interval);
							// 调用异步方法终止定位
							//上传坐标点
							uni.getLocation({
								type: 'wgs84',
								success: (res) => {
									let currentTime = new Date().getTime();
									let Trajectory = []
									let Trajectoryinfo = {
										lat: res.latitude,
										lng: res.longitude,
										positionTime: currentTime
									};
									Trajectory.push(Trajectoryinfo);
									uni.setStorageSync('Trajectory', Trajectory);
									that.wxRequest({
										url: `${that.API}/driverService/uploadMinilocus`,
										method: 'POST',
										data: {
											trackType: 3,
											loadingOrderId: taskvalue.loadingOrderId,
											list: Trajectory,
											vehicleNo: taskvalue.vehicleNo,
											driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
										},
										success: res => {
											// uni.showModal({
											// 	title: `${taskvalue.loadingOrderId}上传坐标点到达`+JSON.stringify(res.data)
											// })
											Trajectory = [];
											uni.setStorageSync('Trajectory', Trajectory);
										}
									});
								}
							})
							locationModule.stop(
								{
									appSecurity:taskvalue.appSecurity,
									enterpriseSenderCode:taskvalue.enterpriseSenderCode,
									ShippingNoteNumber: uni.getStorageSync('loadingOrderId'),
									StartCountrySubdivisionCode: taskvalue.shippingRegionCode,
									EndCountrySubdivisionCode: taskvalue.receiptRegionCode,
									StartLongitude: taskvalue.StartLongitude,
									StartLatitude: taskvalue.StartLatitude,
									EndLongitude: taskvalue.EndLongitude,
									EndLatitude: taskvalue.EndLatitude,
									StartLocationText: taskvalue.shippingCity,
									EndLocationText: taskvalue.receiptCity,
									VehicleNumber: taskvalue.vehicleNo,
									DriverName: taskvalue.driverName
								},
								ret => {
									let reta = ret.code;
									uni.getLocation({
										type: 'wgs84',
										success: function(res) {
											let longitude = res.longitude;
											let latitude = res.latitude;
											if (reta == '停止定位stop成功') {
												uni.setStorageSync('loadingOrderId', '');
												//发送定位回调
												uni.request({
													url: `https://sign.y2t.com/tax/taxInfoUpload`,
													method: 'POST',
													data: {
														vehicleNumber: taskvalue.vehicleNo,
														driverName: taskvalue.driverName,
														shippingNoteNumber: taskvalue.loadingOrderId,
														longitude: longitude,
														latitude: latitude,
														status: 2
													},
													success: res => {
														uni.hideLoading();
														console.log('终止定位结果', ret.code);
													},
													fail: error => {
														uni.hideLoading();
														uni.showToast({
															title: '网络异常！',
															icon: 'none'
														});
													},
													complete: res => {
														if (obj.complete) obj.complete(res);
													}
												});
												console.log('====================================', taskvalue.loadingOrderId);
											}
										}
									});
									// uni.showModal({
									// 	title: '提示',
									// 	content: ret.code,
									// 	showCancel: false,
									// 	success: function(res) {
									// 		if (res.confirm) {
									// 			console.log('用户点击确定');
									// 		}
									// 	}
									// });
								}
							);
							// #endif
							that.checkinFun(taskvalue)
						}
					}
				})
			}else{
				that.checkinFun(taskvalue)
			}
		},
		async checkinFun(taskvalue) {
			let that = this
			// #ifdef MP-WEIXIN
			that.signChannel = 2;
			// #endif
			// #ifdef APP-PLUS
			that.signChannel = 1;
			// #endif
			
			if (that.nextCheckinWriteShippedNum == 0 && that.nextCheckinWriteReceiptedNum == 0 && that.nextCheckinUploadPicture == 0) {
				that.wxRequest({
					url: `${that.API}/miniApp/loadingOrder/checkin`,
					method: 'POST',
					data: {
						clickLocation: 2,
						loadingOrderId: that.orderloadingOrderId,
						checkinSeq: that.ordercheckinSeq,
						signChannel: that.signChannel
					},
					title: '加载中...',
					success: res => {
						that.getdetail();
					}
				});
			} else {
				let isSignShow = await that.$refs.signPop.beforeShow(that.waybillDetail)
				if (isSignShow) {
					that.signPopShow = true
					return
				}
				if (that.imageurl.length > 0) {
					that.imageData = [];
					that.imageurl = '';
				}
				that.shippedNum = '';
				that.receiptedNum = '';
				if (that.waybillDetail.unitStr === '车' || that.waybillDetail.unitStr === '箱') {
					that.shippedNum = '1';
					that.receiptedNum = '1';
				}
				uni.setStorageSync('image', 1);
				that.$refs.popup2.open('center');
			}
		},
		submit() {
			const data = {};
			data.loadingOrderId = this.orderloadingOrderId;
			data.checkinSeq = this.ordercheckinSeq;
			data.signChannel = this.signChannel;
			data.clickLocation = 2;
			if (this.nextCheckinWriteShippedNum == 1) {
				if (this.shippedNum == '') {
					uni.showToast({
						title: '请填写装货数量',
						duration: 2000,
						icon: 'none'
					});
					return;
				} else {
					if (this.waybillDetail.unitStr === '吨') {
						let reg = /^(([1-9]{1}\d{0,1})|(0{1}))(\.\d{1,4})?$/
						if (!reg.test(this.shippedNum)) {
							uni.showToast({
								title: '装货量小数点前最多2位，小数点后最多4位',
								icon: 'none'
							})
							return
						}
					}
					if (this.waybillDetail.unitStr === '立方') {
						let reg = /^(([1-9]{1}\d{0,2})|(0{1}))(\.\d{1,2})?$/
						if (!reg.test(this.shippedNum)) {
							uni.showToast({
								title: '装货量小数点前最多3位，小数点后最多2位',
								icon: 'none'
							})
							return
						}
					}
					if (this.waybillDetail.unitStr === '件') {
						let reg = /^[1-9]\d{0,3}$/
						if (!reg.test(this.shippedNum)) {
							uni.showToast({
								title: '装货量最多4位整数',
								icon: 'none'
							})
							return
						}
					}
					data.shippedNum = this.shippedNum;
				}
			}
			if (this.nextCheckinWriteReceiptedNum == 1) {
				if (this.receiptedNum == '') {
					uni.showToast({
						title: '请填写卸货数量',
						duration: 2000,
						icon: 'none'
					});
					return;
				} else {
					if (this.waybillDetail.unitStr === '吨') {
						let reg = /^(([1-9]{1}\d{0,1})|(0{1}))(\.\d{1,4})?$/
						if (!reg.test(this.receiptedNum)) {
							uni.showToast({
								title: '卸货量小数点前最多2位，小数点后最多4位',
								icon: 'none'
							})
							return
						}
					}
					if (this.waybillDetail.unitStr === '立方') {
						let reg = /^(([1-9]{1}\d{0,2})|(0{1}))(\.\d{1,2})?$/
						if (!reg.test(this.receiptedNum)) {
							uni.showToast({
								title: '卸货量小数点前最多3位，小数点后最多2位',
								icon: 'none'
							})
							return
						}
					}
					if (this.waybillDetail.unitStr === '件') {
						let reg = /^[1-9]\d{0,3}$/
						if (!reg.test(this.receiptedNum)) {
							uni.showToast({
								title: '卸货量最多4位整数',
								icon: 'none'
							})
							return
						}
					}
					data.receiptedNum = this.receiptedNum;
				}
			}
			if (this.nextCheckinUploadPicture == 1) {
				if (this.imageurl == '') {
					uni.showToast({
						title: '请上传图片',
						duration: 2000
					});
					return;
				} else {
					data.receiptCheckPictures = this.imageurl;
				}
			}
			let that = this;
			that.$refs.popup2.close();
			console.log('dd=============>', data);
			that.wxRequest({
				url: `${that.API}/miniApp/loadingOrder/checkin`,
				method: 'POST',
				data: data,
				title: '加载中...',
				success: res => {
					that.getdetail();
				}
			});
		},
		getdetail() {
			this.wxRequest({
				url: `${this.API}/miniApp/loadingOrder/queryDetail`,
				method: 'POST',
				data: {
					loadingOrderId: this.loadingOrderId
				},
				title: '加载中...',
				success: res => {
					this.waybillDetail = res.data.data;
					for (let i = 0; i < this.waybillDetail.length; i++) {
						this.wxRequestData({
							url: `https://restapi.amap.com/v3/geocode/geo?key=7a3ddb7ab9fc4c10f61541024eb3cd65&address=` + this.waybillDetail[i].shippingCity,
							method: 'GET',
							title: '加载中...',
							success: res => {
								this.waybillDetail[i].StartLongitude = res.data.geocodes[0].location.split(',')[0];
								this.waybillDetail[i].StartLatitude = res.data.geocodes[0].location.split(',')[1];
								console.log('d=======定位点===', res.data.geocodes[0].location);
								// console.log("d=======定位点===",res);
								// console.log("d=======定位点===",res);
							}
						});

						this.wxRequestData({
							url: `https://restapi.amap.com/v3/geocode/geo?key=7a3ddb7ab9fc4c10f61541024eb3cd65&address=` + this.waybillDetail[i].receiptCity,
							method: 'GET',
							title: '加载中...',
							success: res => {
								this.waybillDetail[i].EndLongitude = res.data.geocodes[0].location.split(',')[0];
								this.waybillDetail[i].EndLatitude = res.data.geocodes[0].location.split(',')[1];

								console.log('d=======定位点===', res.data.geocodes[0].location);
								// console.log("d=======定位点===",res);
								// console.log("d=======定位点===",res);
							}
						});
					}
				}
			});
		},
		
		// 接单
		receive() {
			return new Promise((resolve, reject) => {
				const that = this
				that.wxRequest({
					url: `${that.API}/miniApp/loadingOrder/receive`,
					method: 'POST',
					data: {
						// #ifdef MP-WEIXIN
						clickLocation: 4,
						// #endif
						// #ifdef APP-PLUS
						clickLocation: 2,
						// #endif
						loadingOrderId: that.waybillDetail.loadingOrderId,
					},
					title: '接单中...',
					success: res => {
						uni.showToast({
							title: '抢单成功！',
							icon: 'none'
						});
						that.$refs.popup3.close();
						resolve()
						that.getdetail();
					},
					fail: err => {
						reject()
					}
				})
			})
		},
		createCircleFenceIsSuccess(taskvalue) {
			return new Promise((resolve, reject) => {
				let that = this
				that.wxRequest({
					url: `${that.API}/fance/waybillFence/createCircleFenceIsSuccess?waybillId=${taskvalue.waybillId}`,
					method: 'get',
					title: '加载中...',
					success: res => {
						resolve(res.data)
					},
					fail: err => {
						reject(err)
					}
				})
			})
		},
		cronJsFance(taskvalue, res){
			let that = this
			console.log(that)
			that.wxRequest({
				url: `${that.API}/fance/waybillFence/cronJsFance`,
				method: 'POST',
				data: {
					vehicleNo: taskvalue.vehicleNo,
					driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile,
					trackType: 2,
					driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
					loadingOrderId: taskvalue.loadingOrderId,
					lat: res.latitude,
					lng: res.longitude
				},
				complete: res => {
					if (res.data && res.data.code == 0) {
						if (uni.getStorageSync('gpsUploadTime') == 0) {
							that.logFn(`上传成功cronJsFance`)
						}
						uni.setStorageSync('gpsUploadTime', new Date().getTime())
					} else {
						if (uni.getStorageSync('gpsUploadTime') == 0) {
							that.logFn(`上传失败cronJsFance，${(res.data && res.data.msg) ? res.data.msg : ''}`)
						}
					}
				},
				success: res => {
					
				}
			})
			that.taxInfoUpload(taskvalue, res)
		},
		uploadMinilocus(taskvalue, res){
			let Trajectory = [];
			let currentTime = new Date().getTime()
			let Trajectoryinfo = {
				lat: res.latitude,
				lng: res.longitude,
				positionTime: currentTime
			};
			Trajectory.push(Trajectoryinfo);
			let that = this
			that.wxRequest({
				url: `${that.API}/driverService/uploadMinilocus`,
				method: 'POST',
				data: {
					trackType: 2,
					loadingOrderId: taskvalue.loadingOrderId,
					list: Trajectory,
					
					vehicleNo: taskvalue.vehicleNo,
					driverTel: uni.getStorageSync(that.DATA_KEY.userInfo).mobile
				},
				complete: res => {
					console.log(res)
					if (res.data && res.data.code == 0) {
						if (uni.getStorageSync('gpsUploadTime') == 0) {
							that.logFn(`上传成功uploadMinilocus`)
						}
						uni.setStorageSync('gpsUploadTime', new Date().getTime())
					} else {
						if (uni.getStorageSync('gpsUploadTime') == 0) {
							that.logFn(`上传失败uploadMinilocus，${(res.data && res.data.msg) ? res.data.msg : ''}`)
							uni.setStorageSync('gpsUploadTime', new Date().getTime())
						}
					}
				},
				success: res => {
					
				}
			})
			that.taxInfoUpload(taskvalue, res)
		},
		taxInfoUpload(taskvalue, res) {
			// #ifdef APP-PLUS
			uni.request({
				url: `https://sign.y2t.com/tax/taxInfoUpload`,
				method: 'POST',
				data: { 
					vehicleNumber: taskvalue.vehicleNo,
					driverName: taskvalue.driverName,
					shippingNoteNumber: taskvalue.loadingOrderId,
					longitude: res.longitude,
					latitude: res.latitude,
					status: 1
				},
				success: res => {
				},
				fail: error => {
				}
			});
			// #endif
		},
		getShippingStatus(taskvalue){
			return new Promise((resolve, reject) => {
				let that = this
				that.wxRequest({
					url: `${that.API}/fance/waybillFence/getShippingStatus?id=${taskvalue.loadingOrderId}`,
					method: 'get',
					title: '加载中...',
					success: res => {
						resolve(res.data.data.shippingStatus)
					},
					fail: err => {
						reject(err)
					}
				})
			})
		},
		logFn(content) {
			this.wxRequest({
				url: `${this.API}/miniApp/loadingOrder/saveTrajectoryLog`,
				method: 'POST',
				data: {
					loadingOrderId: this.orderloadingOrderId,
					driverId: uni.getStorageSync(this.DATA_KEY.userInfo).driverId,
					content: JSON.stringify({
						platform: uni.getSystemInfoSync().platform,
						// #ifdef MP-WEIXIN
						wxVersion: wx.getAppBaseInfo().SDKVersion,
						// #endif
						title: '',
						result: content
					})
				},
				success: res => {
					
				}
			})
		}
	},
	onLoad: function(options) {
		this.userInfo = uni.getStorageSync(this.DATA_KEY.userInfo);
		this.billNo = JSON.parse(options.data).billNo;
		// this.billNo = '1376376418803385129';
		this.loadingOrderId = JSON.parse(options.data).loadingOrderId;
		// console.log('ddds============', JSON.parse(options.data));
		// this.formData.orderId = this.billNo;
		//车辆颜色
		this.wxRequest({
			url: `${this.API}/driverService/queryDic`,
			method: 'POST',
			data: ['CARGO_TYPE'],
			success: res => {
				console.log('ddddd===================', res.data.data.CARGO_TYPE);
				this.array = res.data.data.CARGO_TYPE;
			}
		});

		this.getdetail();
	}
};
</script>

<style lang="scss">
	.tips{
		background: #fdefec;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #f00;
		font-size: 28rpx;
		padding: 12rpx 24rpx;
		.som{
			font-size: 24rpx;
			// margin-top: 4rpx;
		}
		.tip-img{
			width: 40rpx;
			height: 40rpx;
		}
		.tip-info{
			flex: 1;
			margin: 0 24rpx;
		}
		.tip-btn{
			padding: 0 12rpx;
		}
	}
page {
	font-size: 30rpx;
}
.row-css {
	display: flex;
	flex-direction: row;
}

.column-css {
	display: flex;
	flex-direction: column;
}
.view-deltail {
	text-align: center;
	background: #2b7cff;
	padding: 20rpx 0;
	color: #ffffff;
	border-radius: 5rpx;
}
.view-rodio {
	display: flex;
	width: 15rpx;
	height: 15rpx;
	margin: 7.5rpx;
	border-radius: 50%;
}

.line {
	background-color: #d9d9d9;
	margin-left: 14rpx;
	height: 50rpx;
	width: 1rpx;
}

.code-view {
	width: 140rpx;
	text-align: center;
	padding: 12rpx 0;
	background: #ffffff;
	border: 1rpx solid #eeeeee;
	border-radius: 2rpx;

	width: 200rpx;
	text-align: center;
	font-size: 24rpx;
	margin-left: 20rpx;
	color: #ffffff;
	background: #2979ff;
	border-radius: 2rpx;
	padding: 15rpx 0;
}

.input-code {
	width: 140rpx;
	text-align: center;
	padding: 12rpx 0;
	background: #ffffff;
	border: 1rpx solid #eeeeee;
	border-radius: 2rpx;
}
.view-cente {
	background: #ffffff;
	padding: 0 30rpx;
}
.view-cente-cle {
	padding: 25rpx 0;
	border-bottom: 1rpx solid #eeeeee;
}
.view-cente-cle-text {
	width: 180rpx;
	color: #5f6579;
}
.view-button {
	display: flex;
	flex: 1;
	background: #fb8536;
	border-radius: 5rpx;
	padding: 20rpx;
	margin: 30rpx;
	justify-content: center;
	color: #ffffff;
}
.button-view{
	width: 49%;
	justify-content: center; 
	padding: 30rpx;
}
</style>
